﻿var table;
$(document).ready(function () {
    GetTable();
    $("#addBut").click(function () {
        location.href = "/Questions/QuestionAdd";
    });
    $("#Searchbtn").bind("click", function () { //按钮 触发table重新请求服务器
        table.fnDraw();
    });
});
function GetTable() {
    table = $('#ProvinceDIV').dataTable({
        "bServerSide": true, //这个用来指明是通过服务端来取数据
        "sAjaxSource": "/Questions/GetAllInfos", //这个是请求的地址
        //"info": true,
        "bFilter": false,
        "iDisplayLength": 15,
        "aoColumns": [
            { "mDataProp": "QuestionID", "sTitle": "ID", "sDefaultContent": "" },
            { "mDataProp": "ModalityName", "sTitle": "Modality", "sDefaultContent": "" },
            { "mDataProp": "ProductName", "sTitle": "Product", "sDefaultContent": "" },
            { "mDataProp": "QuestionContent", "sTitle": "Test Question", "sDefaultContent": "" },
            { "mDataProp": "Level", "sTitle": "Level", "sDefaultContent": "" },
            { "mDataProp": "Block", "sTitle": "Block", "sDefaultContent": "" },
            { "mDataProp": "IsActive", "sTitle": "Is Active", "sDefaultContent": "" }
        ],
        "aoColumnDefs": [
           {
               "targets": [1], // 目标列位置，下标从0开始
               "data": "LibraryName", // 数据列名
               "render": function (data, type, full) { // 返回自定义内容
                   return "<a href='javascript:void(0)' style=\"text-decoration:none;outline:none\" onclick=\"javascript:UpdateInfo('" + full.LibraryID + "')\" class='Link'>" + data + "</a>";
               }
           },
           {
               "targets": [2], // 目标列位置，下标从0开始
               "data": "IsActive", // 数据列名
               "render": function (data, type, full) { // 返回自定义内容
                   if (full.IsActive == 0) {
                       return "Active";
                   }
                   else {
                       return "InActive";
                   }
               }
           },
           {
               "targets": 0, //第一列隐藏
               "visible": false,
               "searchable": false
           }
        ],
        "fnServerParams": function (aoData) { //查询条件
            aoData.push(
                { "name": "LibraryName", "value": $("#LibraryName").val() },
            { "name": "isactive", "value": $("#isActive").val() }
            );
        },
        "bLengthChange": false,
        "sPaginationType": "full_numbers"
    });
}
/* Add a click handler to the rows - this could be used as a callback */


function UpdateInfo(parameters) {
    location.href = "/Questions/QuestionUpdate/" + parameters;
}
